#include<bits/stdc++.h>
using namespace std;
int n,k,f[1000010],dp[1000010];
vector<int> edge[1000010];
int work(int u,int dep){
	if(dep>k) return dp[u];
	int sum=0;
	for(auto &i:edge[u])
		sum+=work(i,dep+1);
	return min(sum,dp[u]);
}
void dfs(int u){
	if(f[u]!=1) dp[u]=1;
	for(auto &i:edge[u]){
		dfs(i);
		dp[u]+=work(i,2);
	}
}
int main(){
	freopen("lost.in","r",stdin);
	freopen("lost.out","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&f[i]);
		if(i!=1) edge[f[i]].push_back(i);
	}
	if(k==1){
		int num=0;
		for(int i=1;i<=n;i++)
			if(f[i]!=1) num++;
		printf("%d",num);
		return 0;
	}
	dfs(1);
	printf("%d",dp[1]);
	return 0;
}
